package com.atguigu.gmall.serviceutil.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/8/30 21:28
 */
@Data
@ConfigurationProperties(prefix = "app.thread-pool")
public class AppThreadPoolProperties {
    private int corePoolSize;
    private int maxPoolSize;
    private Long keepAliveTime;  // 空闲线程存活时间
    private int queueCapacity;
    private TimeUnit unit=TimeUnit.MINUTES;
    // 线程池拒绝策略
    // 1. AbortPolicy:丢弃任务并抛出RejectedExecutionException异常
    // 2. CallerRunsPolicy:由调用者线程来执行任务
    // 3. DiscardOldestPolicy:抛弃队列中等待最久的任务，然后重新尝试执行任务（重复此过程）
    // 4. DiscardPolicy:直接丢弃任务，不予任何处理
    private RejectedExecutionHandler rejectedExecutionHandler=new ThreadPoolExecutor.CallerRunsPolicy();
}
